package common;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;

public class VSM_AboutScreen extends JDialog implements ActionListener
{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5427216122151235142L;
	
	private final JButton closeButton = new JButton("Close");
	private final JPanel panelBack = new JPanel();
	private final JPanel panelButton = new JPanel();
	private final JPanel panelLogo = new JPanel();
	private final JTextArea textArea = new JTextArea();
	
	public VSM_AboutScreen(JFrame parent, String title)
	{
		super(parent,title);
		
		VSM_LogoPanel logo = new VSM_LogoPanel();
		
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		this.setLayout(new BorderLayout());
		this.setResizable(false);
		
		this.add(panelBack,BorderLayout.CENTER);
		this.add(panelLogo,BorderLayout.WEST);
		this.add(panelButton,BorderLayout.SOUTH);
		
		panelBack.add(textArea);
		
		panelLogo.add(logo);
		
		panelBack.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.gray),"Visual Sensor Monitor"));
		panelLogo.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.gray),"FT - School of Technology"));
		
		
		panelBack.setBackground(Color.white);
		panelLogo.setBackground(Color.white);
		
		textArea.setFocusable(false);
		
		textArea.append(getAboutText());
		
		panelButton.add(closeButton);
		
		this.setSize(getPreferredSize().width, getPreferredSize().height + 25);
		this.setLocationRelativeTo(parent);
		
		closeButton.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		if(e.getSource() == closeButton)
		{
			this.dispose();
		}

	}
	
	private String getAboutText()
	{
		String aboutText = "";
		aboutText += VSM_ProjectInfo.getProjectinstitution();
		aboutText += "\n";
		
		aboutText += VSM_ProjectInfo.getProjectdepartment();
		aboutText += "\n\n";
		
		aboutText += VSM_ProjectInfo.getProjectname();
		aboutText += "\n";
		
		aboutText += VSM_ProjectInfo.getProjectmission();
		aboutText += "\n";
		
		aboutText += VSM_ProjectInfo.getProjectversion();
		aboutText += "\n";
		
		aboutText += "Implementation start date: " + VSM_ProjectInfo.getProjectstartdate();
		aboutText += "\n";
		
		aboutText += "Implementation end date: " + VSM_ProjectInfo.getProjectdate();
		aboutText += "\n\n";
		
		String[] projectauthors = VSM_ProjectInfo.getProjectauthors();
		
		for(String author : projectauthors)
		{
			aboutText += " " + author + "\n";
		}
		aboutText += "\n";
		
		aboutText += VSM_ProjectInfo.getProjectcopyright();
		return aboutText;
	}

}
